#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
#include <ctype.h>

#define SHOW_DEFAULT 0
#define SHOW_HIGHLIGHT 1
#define SHOW_NOBOLD 22
#define SHOW_UNDERLINE 4
#define SHOW_NOUNDERLINE 24
#define SHOW_BLINK 5
#define SHOW_NOBLINK 25
#define SHOW_INVERT 7
#define SHOW_NOINVERT 27

#define CLR_BLACK 30
#define CLR_RED 31
#define CLR_GREEN 32
#define CLR_YELLOW 33
#define CLR_BLUE 34
#define CLR_MAGENTA 35
#define CLR_CYAN 36
#define CLR_WHITE 37

#define CLR_BK_BLACK 40
#define CLR_BK_RED 41
#define CLR_BK_GREEN 42
#define CLR_BK_YELLOW 43
#define CLR_BK_BLUE 44
#define CLR_BK_MAGENTA 45
#define CLR_BK_CYAN 46
#define CLR_BK_WHITE 47

#define CLR_HEADER "\033[%d;%d;%dm"
#define CLR_TAIL "\033[0m"
#define COLOR_STR "%s%s%s"

void print_hex(const unsigned char *data, int len)
{
	int i = 0, j = 0;

	printf("	   0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f    0123456789abcdef\n");
	while (i < len)
	{
		printf("%08x  ", i);
		for (j = i; j < (i + 16); j++)
		{
			if (j < len)
			{
				printf("%02x ", data[j]);
			}
			else
			{
				printf("%s", "   ");
			}
			if (j == (i + 7))
			{
				printf(" ");
			}
		}

		printf(" | ");

		for (j = i; j < (i + 16); j++)
		{
			if (j < len)
			{
				printf("%c", isprint(data[j]) ? data[j] : '.');
			}
			else
			{
				printf("%c", ' ');
			}
		}
		i += 16;
		printf(" | ");
		printf("\n");
	}
}
